package com.mall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mall.entity.Users;
import com.mall.user.mapper.UsersMapper;
import com.mall.user.service.UserCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserCheckServiceImpl implements UserCheckService {

    @Autowired
    private UsersMapper usersMapper;


    @Override
    public Users getUser(String username) {
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Users::getUsername,username);
        Users user = usersMapper.selectOne(wrapper);
        return user;
    }

    public int save(Users user) {
        int result = usersMapper.insert(user);
        return result;
    }

    public List<Users> getUserList() {
        List<Users> usersList = usersMapper.selectList(null);
        return usersList;
    }

    @Override
    public List<Users> deleteUser(String userId) {
        int i = usersMapper.deleteById(userId);
        if (i > 0) {
            return usersMapper.selectList(null);
        }
        return null;
    }

    @Override
    public List<Users> selectByUsername(String username) {
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.lambda().like(Users::getUsername,username);
        List<Users> usersList = usersMapper.selectList(wrapper);
        return usersList;
    }

}
